package com.controller;

import com.entity.UserGroupEntity;
import com.service.UserGroupService;
import com.service.UserService;
import top.appx.espring.annotation.Action;
import top.appx.espring.annotation.Autowired;
import top.appx.espring.annotation.Controller;
import top.appx.espring.annotation.RequestMapping;
import top.appx.espring.vo.ResultVO;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@Controller("/UserGroup")
public class UserGroupController extends BaseController<UserGroupEntity> {

    @Autowired
    private UserGroupService userGroupService;

    public Object tree(){
        List<UserGroupEntity> list = new ArrayList<UserGroupEntity>();
        list.addAll(userGroupService.query());
        List<Object> rList = new ArrayList<Object>();
        rList.add(ResultVO.data().p("name","全部").p("entity",ResultVO.data().p("flag",2).p("id",0)));
        for (UserGroupEntity userGroupEntity:list) {
            rList.add(ResultVO.data().p("name",userGroupEntity.getName()).p("icon",userGroupEntity.getIcon()).p("entity",ResultVO.data().p("flag",2).p("id",userGroupEntity.getId())));
        }
        return ResultVO.data().p("name","用户分组").p("open",true).p("children",rList).p("entity",ResultVO.data().p("flag",1));
    }

    public Object query(){
        return userGroupService.query();
    }

    public void add(UserGroupEntity userGroupEntity){
        userGroupService.add(userGroupEntity);
    }


    public void modify(UserGroupEntity userGroupEntity){
        userGroupService.modify(userGroupEntity);
    }
    @Action("delByIds")
    public void delByIds(HttpServletRequest request){
        userGroupService.delByIds(requestIds(request));
    }


}
